$(function() {
	
    $("a.bl").click(function(e) {
        var rel = $(this).attr("rel");
        $("#rel").attr("value", rel);
        $(this).overlay({load: true, target: "#dialog", fixed: false, onBeforeLoad: function(){ $("#download_form").show(); $("#downloaded_msg").hide() } });
		
    });

});

var download_form_visible = true;

function sendDownloadForm()
{
	var name = $("#user_name").val();
	var mail = $("#user_email").val();
	var rel = $("#rel").val();
	
	if(mail.length < 1) {
		alert("Please, provide your email address.");
		return false;
	}
	
	var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	if(!pattern.test(mail)){         
		alert("Invalid Email Adress");  
		return false; 
	}
	

	/*$.ajax({
		url: "clientdownloads.php",
		type: "POST",
		data: {
			rel: rel,
			name: name,
			mail: mail,
			last_url: window.location.href
		},
		success: function(data) {
			
			$("#download_form").hide();
			$("#downloaded_msg").show();
		}
	});*/
	
	$.ajax({
		url: "clientdownloads.php",
		type: "POST",
		data: {
			rel: rel,
			name: name,
			mail: mail
		},
		success: function(data) {
			
			if ( data != 'error' )
				window.location = window.location.href + '/download/' + rel;
			else
				alert('Error occured.');
			
		}
	});
}